//
//  GMFShapeButton.m
//  SplunkMobile
//
//  Created by lijunying on 2/27/2016.
//  Copyright © 2016 Gome. All rights reserved.
//

#import "GMFShapeButton.h"

@implementation GMFShapeButton

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.titleLabel.font = [UIFont systemFontOfSize:10];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    float fltImageViewWidth = 24;
    float fltImageViewX = (self.frame.size.width - fltImageViewWidth) * 0.5;
    
    [self.imageView setFrame:CGRectMake(fltImageViewX, fltImageViewX - 4, fltImageViewWidth, fltImageViewWidth)];
    [self.titleLabel setFrame:CGRectMake(0, fltButtonWidth - 9 - 4, fltButtonWidth, 15)];
    
}

- (void)selectOrUnselectTheButton:(BOOL)isSelected
{
    if (isSelected)
    {
        [self setShapeType:_intButtonType highlighted:YES];
    }
    else
    {
        [self setShapeType:_intButtonType highlighted:NO];
    }
    
}


- (void)setShapeType:(NSInteger)type highlighted:(BOOL)isSelected
{
//    _intButtonType = 0;
    
    if (type == 0)
    {
        if (!isSelected)
        {
            [self setImage:[UIImage imageNamed:@"btn_line"] forState:UIControlStateNormal];
            [self setTitleColor:GMKColor(153, 153, 153) forState:UIControlStateNormal];
        }
        else
        {
            [self setImage:[UIImage imageNamed:@"btn_line2"] forState:UIControlStateNormal];
            [self setTitleColor:kColorDefaultRed forState:UIControlStateNormal];
        }
    }
    else if (type == 1)
    {
        if (!isSelected)
        {
            [self setImage:[UIImage imageNamed:@"btn_curve"] forState:UIControlStateNormal];
            [self setTitleColor:GMKColor(153, 153, 153) forState:UIControlStateNormal];
        }
        else
        {
            [self setImage:[UIImage imageNamed:@"btn_curve2"] forState:UIControlStateNormal];
            [self setTitleColor:kColorDefaultRed forState:UIControlStateNormal];
        }
    }
    else if (type == 2)
    {
        if (!isSelected)
        {
            [self setImage:[UIImage imageNamed:@"btn_rectangle"] forState:UIControlStateNormal];
            [self setTitleColor:GMKColor(153, 153, 153) forState:UIControlStateNormal];
        }
        else
        {
            [self setImage:[UIImage imageNamed:@"btn_rectangle2"] forState:UIControlStateNormal];
            [self setTitleColor:kColorDefaultRed forState:UIControlStateNormal];
        }
    }
    else if (type == 3)
    {
        if (!isSelected)
        {
            [self setImage:[UIImage imageNamed:@"btn_ellipse"] forState:UIControlStateNormal];
            [self setTitleColor:GMKColor(153, 153, 153) forState:UIControlStateNormal];
        }
        else
        {
            [self setImage:[UIImage imageNamed:@"btn_ellipse2"] forState:UIControlStateNormal];
            [self setTitleColor:kColorDefaultRed forState:UIControlStateNormal];
        }
    }
}





@end















